import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  base: 'wings-nav',
  plugins: [vue()],
  resolve: {
    alias: {
      '@': '/src',
      'components': '/src/components',
      'utils': '/src/utils'
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true, // 允许链式调用的换行
      },
      scss: {
        additionalData: `@import "@/style/main.scss";`,
      },
    },
  },
  build: {
    emptyOutDir: false, // 在打包时不清空dist目录
  },
  server: {
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    host: true,
    port: 8520,
    open: false, // 是否服务启动时自动打开浏览器
    cors: true, // 是否允许跨域
    proxy: {
      ['/v1/ctrl/blocks']: {
        target: 'https://v2fd.ujuji.com',
        // rewrite: (path: any) => path.replace(new RegExp(`^${base}`, 'g'), ''),
      },
      '/wing-key': {
        target: 'https://gitee.com/lwj-wing/wings-nav',
        changeOrigin: true,
        secure: false, // 禁用SSL验证
        rewrite: (path: any) => {
          // '^/wing-key': '/lwj-wing/wings-nav/raw/master' // 修改请求路径
          return path.replace(/^\/wing-key/g, '/lwj-wing/wings-nav/raw/master')
        }
      }

  
  },
  },
})